﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.produceLinq;

namespace dhDataAcess.produceDAL
{
   public  class machineTableDAL
    {
            string  tableName = "machineTable";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public machineTableDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入机器号表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int machineTableInsert(machineTableModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
           // string insertstr = "insert into pbomMaster (mark,updateUser,updateDate,createUser,createDate,checkDate,spr,zbr,awgight,bweight,machineType,custNum,pname) values(@mark,@updateUser,@updateDate,@createUser,@createDate,@checkDate,@spr,@zbr,@awgight,@bweight,@machineType,@custNum,@pname)";
            string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();

                                SqlParameter[] para = {
                                                         //  new SqlParameter ("@recordid",row .recordid   ),
                                                         new SqlParameter ("@billStatus",row.billStatus    ),
                                                        new SqlParameter ("@machineNo",row .machineNo  ),
                                                        new SqlParameter ("@machinetype",row .machinetype  ),
                                                        new SqlParameter ("@panme",row .panme  ),
                                                        new SqlParameter ("@pw",row .pw  ),
                                             
                                                    };
             cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新机器号表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int machineTableUpdate(machineTableModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
          //  string updatestr = " update machineTable set pw=@pw,billStatus=@billStatus,panme=@panme,machinetype=@machinetype,machineNo=@machineNo,recordid=@recordid where recordid=@recordid";
            SqlParameter[] para = {
                                                    // new SqlParameter ("@recordid",row .recordid   ),
                                                     new SqlParameter ("@billStatus",row.billStatus    ),
                                                     new SqlParameter ("@machineNo",row .machineNo  ),
                                                        new SqlParameter ("@machinetype",row .machinetype  ),
                                                        new SqlParameter ("@panme",row .panme  ),
                                                        new SqlParameter ("@pw",row .pw  ),
                                             
                                                    };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行机器号表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int machineTableDel(string recordid)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr (tableName).ToString();
            SqlParameter[] para = {
                                     
                                        new SqlParameter ("@recordid",recordid )
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr ;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
